import { Dictionary } from 'express-serve-static-core';

export function getOrFail<T>(dict: Dictionary<T>, memberName: string): Promise<T> {
	return new Promise((resolve, reject) => {
		let member = dict[memberName];
		if (member) {
			resolve(member);
		} else {
			reject();
		}
	});
}

export function getFirstDefinedOrDefault<K, V>(map: Map<K, V>, keys: Array<K>, orElse: V) {
	keys.forEach(k => {
		if (map.has(k)) {
			return map.get(k);
		}
	});
	return orElse;
}
